package com.example.playbox

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity

class PersonalCenterActivity : AppCompatActivity(), View.OnClickListener {
    // 定义组件
    private lateinit var tvStuNumber: TextView
    private lateinit var btnLogout: Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_personal_center)

        btnLogout = findViewById(R.id.btn_logout)
        btnLogout.setOnClickListener(this)

        // 取出登录时的登录名
        tvStuNumber = findViewById(R.id.tv_student_number)
        val stuNumber = intent.getStringExtra("wangjiu")
        tvStuNumber.text = stuNumber

        // 返回主界面
        val btnBack: Button = findViewById(R.id.bt_back)
        btnBack.setOnClickListener { finish() }

        // 点击个人信息按钮
        val btnUserInfo: Button = findViewById(R.id.btn_user_info)
        btnUserInfo.setOnClickListener {
            val intent = Intent(applicationContext, MyIFActivity::class.java)
            val bundle = Bundle()
            bundle.putString("stu_number1", tvStuNumber.text.toString())
            intent.putExtras(bundle)
            startActivity(intent)
        }
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.btn_logout -> {
                val intentInsert = Intent()
                intentInsert.setClass(this@PersonalCenterActivity, BackActivity::class.java)
                startActivity(intentInsert)
            }
        }
    }
}